//
//  MeasureController.swift
//  foreign_swift
//
//  Created by 黄敦仁 on 15/4/22.
//  Copyright (c) 2015年 hdr. All rights reserved.
//

import UIKit

class MeasureController: UIViewController {
    
    var measureCircle:MeasureCircle!
    
    init() {
        super.init(nibName: nil, bundle: nil)
        
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        initNavigationBar()
        
        initAvatar()
        
        initMeasureCircle()
    }
    
    override func viewDidAppear(animated: Bool) {
        measureCircle.startAnimation()
    }
    
    func initNavigationBar(){
        
        self.edgesForExtendedLayout = UIRectEdge.None
        
        self.title = CurUser.name
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "navigationBar_share.png"), style: UIBarButtonItemStyle.Done, target: self, action: "onShareCilck")

        self.navigationItem.rightBarButtonItem?.tintColor = UIColor.whiteColor()
        
        self.navigationController?.navigationBar.backgroundColor = UIColor.themeColor

    }
    
    func initAvatar(){
        let avatarIv = UIImageView(frame: CGRect(x: 10, y: CGFloat(4.5), width: 35, height: 35))
        let defaultImage:UIImage
        if CurUser.gender == 0 {
            defaultImage = UIImage(named:"common_headPortraitDefault_female.png")!
        }else{
            defaultImage = UIImage(named:"common_headPortraitDefault_male.png")!
        }
        avatarIv.image = defaultImage
        if let avatarUrl = CurUser.avatar {
            avatarIv.sd_setImageWithURL(NSURL(string:avatarUrl))
        }

        self.navigationController?.navigationBar.addSubview(avatarIv)
    }
    
    func initMeasureCircle(){
        self.measureCircle = MeasureCircle()
        
        self.view.addSubview(measureCircle)
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func onShareCilck(){
        println("点击了右边的分享")
    }
    
    func onAvatarClick(){
        println("头像被点击了")
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
